﻿@using RoadFlow.Utility;
<table cellpadding="0" cellspacing="1" border="0" width="99%" align="center" style="margin-top:6px;">
    <tr>
        <td style="vertical-align:top;width:50%;" id="steptd">
            <fieldset style="padding:4px; min-height:200px; border:1px solid #e8e8e8;">
                <legend>&nbsp;接收步骤和人员&nbsp;</legend>
                <table cellpadding="0" cellspacing="1" border="0" width="97%" align="center" style="margin-top:0px;">
                    @Html.Raw(ViewData["nextSteps"])
                </table>
            </fieldset>
        </td>
    </tr>
</table>

<div style="width:95%; margin:12px auto 0 auto; text-align:center;">
    <input type="button" class="mybutton" onclick="return confirm1();" name="Save" value="&nbsp;确&nbsp;定&nbsp;" style="margin-right:5px;" />
    <input type="button" class="mybutton" value="&nbsp;取&nbsp;消&nbsp;" onclick="new RoadUI.Window().close();" />
</div>
<script type="text/javascript">
    var frame = null;
    var openerid = '@ViewData["openerId"]';
    var nextStepsCount = @ViewData["nextStepCount"];
    var isAddWrite = "1" == "@ViewData["isAddWrite"]";
    var isFreedomSend = "1" == "@ViewData["freedomSend"]";//是否是自由发送
    var iframeid = '@ViewData["tabId"]';
    var iframeid1 = '@ViewData["iframeId"]';
    var autoCinfirm = "1" == "@ViewData["autoConfirm"]";//是否自动确认
    var isDebug = false;
    var isCompleted = false;//是否完成
    $(function ()
    {
        var iframes = top.frames;
        for (var i = 0; i < iframes.length; i++)
        {
            var fname = "";
            try
            {
                fname = iframes[i].name;
            }
            catch (e)
            {
                fname = "";
            }
            if (fname == openerid + "_iframe")
            {
                frame = iframes[i];
                break;
            }
        }
        if (frame == null)
        {
            frame = parent;
        }
        if (frame == null)
        {
            alert("未找到父窗口!");
            return;
        }
        //如果后面没有步骤，则完成该流程实例
        if (nextStepsCount == 0)
        {
            var options = {};
            options.type = "completed";
            options.steps = [];
            frame.formSubmit(options);
            new RoadUI.Window().close();
        }
        else if (nextStepsCount > 2)
        {
            top.mainDialog.resize(550, (nextStepsCount - 2) * 45 + 300);
        }
        isCompleted = nextStepsCount == 0;
        if (isCompleted)
        {
            $("#steptd").hide();
        }
        //自动确认
        if (autoCinfirm) {
            isSubmit = true;
            $("input[name='step']").each(function () {
                var step = $(this).val();
                var member = $("#user_" + step).val() || "";
                if (member.length == 0) {
                    isSubmit = false;
                    return false;
                }
                var $completedTime_ = $("#CompletedTime_" + step);
                if ($completedTime_.size() > 0 && $completedTime_.val().length == 0) {
                    isSubmit = false;
                    return false;
                }
            });
            if (isSubmit) {
                $("input[name='step']").prop("checked", true);
                confirm1();
            }
        }
    });
    function confirm1()
    {
        if (isCompleted)
        {
            var options = {};
            options.type = "completed";
            options.steps = [];
            frame.formSubmit(options);
            new RoadUI.Window().close();
        }
        var opts = {};
        opts.type = isAddWrite ? "addwrite" : isFreedomSend ? "freesubmit" : "submit";
        opts.steps = [];
        var isSubmit = true;
        $(":checked[name='step']").each(function ()
        {
            var step = $(this).val();
            var member = $("#user_" + step).val() || "";
            if (member.length == 0)
            {
                alert($(this).next().text() + "步骤没有选择处理人员!");
                isSubmit = false;
                return false;
            }
            var $completedTime_ = $("#CompletedTime_" + step);
            if ($completedTime_.size() > 0 && $completedTime_.val().length == 0)
            {
                alert($(this).next().text() + "步骤没有设置完成时间!");
                isSubmit = false;
                return false;
            }
            opts.steps.push({ id: step, member: member, completedtime: $completedTime_.val()});
        });
        if (!isSubmit)
        {
            return false;
        }
        if (opts.steps.length == 0)
        {
            alert("没有选择要处理的步骤!");
            return false;
        }
        if (isSubmit)
        {
            frame.formSubmit(opts);
            new RoadUI.Window().close();
        }
    }
</script>